//
//  PTStuLSMyPartJobCell.m
//  PlanTech
//
//  Created by ruifeng song on 2018/7/23.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLSMyPartJobCell.h"
#import "SINACalendarUtils.h"

@implementation PTStuLSMyPartJobCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
         [self.callPhoneButton addTarget:self action:@selector(onClickCallPhoneButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

-(void)updateServiceMyPartJobCellWith:(LifeServiceMyMissionsModel *)listModel
{
    self.missionUUID = listModel.uuid;
    
    if (listModel.employer.avatar && listModel.employer.avatar.length > 0) {
        
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:listModel.employer.avatar] placeholderImage:[UIImage imageNamed:@"list_header_default_img"]];
    }
    else
    {
        [self.headerImageView setImage:[UIImage imageNamed:@"list_header_default_img"]
         ];
    }
    
    self.phoneNum = listModel.employer.phone;
    
    NSString * serviceType = @"";
    NSString * serviceContentStr = @"";
    NSString * userAddressStr = @"";
    NSString * serviceName = @"";
    NSString * serviceAddress = @"";
    
    switch ([listModel.type integerValue]) {
        case 8:
            serviceType = @"代取快递";
            serviceContentStr = @"快递点：";
            userAddressStr = @"收货地址：";
            serviceName = listModel.destinationAddress;
            serviceAddress = listModel.employerAddress;
            break;
        case 9:
            serviceType = @"打印复印";
            serviceContentStr = @"打印份数：";
            userAddressStr = @"打印地点：";
            if (listModel.copies ==nil) {
                listModel.copies = [NSNumber numberWithInteger:0];
            }
            serviceName = [NSString stringWithFormat:@"%@",listModel.copies];
            serviceAddress = listModel.destinationAddress;
            break;
        case 10:
            serviceType = @"捎饭带饭";
            serviceContentStr = @"餐厅名称：";
            userAddressStr = @"餐厅地址：";
            serviceName = listModel.destinationName;
            serviceAddress = listModel.destinationAddress;
            break;
        case 11:
            serviceType = @"超市代购";
            serviceContentStr = @"超市名称：";
            userAddressStr = @"超市地点：";
            serviceName = listModel.destinationName;
            serviceAddress = listModel.destinationAddress;
            break;
    }
    //快递点
    self.serviceContentLabel.text = [NSString stringWithFormat:@"%@%@",serviceContentStr,serviceName];
    
    //收货地址
    self.userAddressLabel.text = [NSString stringWithFormat:@"%@%@",userAddressStr,serviceAddress];
    
    self.userNameLabel.text = [NSString stringWithFormat:@"%@（%@）",listModel.employer.name,serviceType];
    
    switch ([listModel.status integerValue]) {
        case PTLifeServiceMission_NormalStatus:
        {
            self.statusLabel.text = @"待完成";
            self.callPhoneButton.hidden = NO;
            
            self.firstButton.hidden = NO;
            [self.firstButton setTitle:@"完成兼职" forState:UIControlStateNormal];

            self.firstButton.tag = MyReleaseOrder_FinishType;
 
            self.firstButton.layer.borderWidth = 1;
            self.firstButton.layer.borderColor = PTColor_349ef7.CGColor;
        }
            break;
        case PTLifeServiceMission_FinishStatus:
        {
            self.statusLabel.text = @"待评价";
            self.callPhoneButton.hidden = NO;
            self.firstButton.hidden = YES;
        }
            break;
        case PTLifeServiceMission_CommentStatus:
        {
            self.statusLabel.text = @"已完成";
            self.callPhoneButton.hidden = YES;
            self.firstButton.hidden = NO;
            [self.firstButton setTitle:@"删除订单" forState:UIControlStateNormal];
            self.firstButton.layer.borderWidth = 1;
            self.firstButton.tag = MyReleaseOrder_DeleteType;
            self.firstButton.layer.borderColor = PTColor_ff3a31.CGColor;
        }
            break;
            
        case PTLifeServiceMission_WaitSolveStatus:
        {
            self.statusLabel.text = @"待处理";
            self.callPhoneButton.hidden = NO;
            self.firstButton.hidden = YES;
        }
            break;
    }
    
    if ([listModel.status integerValue] == PTLifeService_CommentStatus) {
        self.commendView.hidden = NO;
    }
    else
    {
        self.commendView.hidden = YES;
    }
    
    //收货时间
    NSString *startimeStr=[NSString stringWithFormat:@"%@",listModel.startTime];
    NSString *endTimeStr=[NSString stringWithFormat:@"%@",listModel.endTime];
    
    self.receiveGoodsLabel.text = [NSString stringWithFormat:@"收货时间：%@-%@",[SINACalendarUtils getDateStringWithTimeStr:startimeStr andFormat:@"MM月dd日 HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:endTimeStr andFormat:@"HH:mm"]];
    
    self.feeLabel.text = [NSString stringWithFormat:@"酬金：%@RMB",listModel.reward];
}

-(void)onClickFirstButton:(UIButton *)sender
{
    if (sender.tag == MyReleaseOrder_FinishType) {
        
        if (self.jobDelegate) {
            
            [self.jobDelegate onClickFinishPartJobItem:self];
        }
    }
    else if (sender.tag == MyReleaseOrder_DeleteType)
    {
        if (self.jobDelegate) {
            [self.jobDelegate onClickDeletePartJobItem:self];
        }
    }
}

-(void)onClickCallPhoneButton:(id)sender
{
    NSMutableString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.phoneNum];
    
    WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"拨打电话" message:string sureBtn:@"确定" cancleBtn:@"取消"];
    
    alertView.resultIndex= ^(NSInteger index) {
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
    };
    [alertView showXLAlertView];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
